<?php
namespace Api\Controller;

use Think\Controller;

class SignController extends Controller {

    public function getDownurl(){
        $audio_id=$_GET['audio_id'];
        $rs = array('code' => 0, 'msg' => '', 'info' =>array());
        $info=array();

        $url='http://music.baidu.com/data/music/links?songIds='.$audio_id;
        var_dump($url);
        $fp = file_get_contents($url);
        var_dump($fp);
        $headers = array();
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, false);

        $contents = curl_exec($curl);
        curl_close($curl);

        $body=json_decode($fp,true);
        $errorCode=$body['errorCode'];
        $songList=$body['data']['songList'];
        //var_dump($body);
        if(!$songList){
            $rs['code'] = 1001;
            $rs['msg'] = '歌曲不存在';
            return $rs;
        }


        $info['audio_link']=$songList[0]['songLink'];
        $info['audio_ext']=$songList[0]['format'];
        $info['time_len']=$songList[0]['time'];
        $info['audio_size']=$songList[0]['size'];
        $info['lrcLink']=$songList[0]['lrcLink'];


        //var_dump($info);exit;
        $rs['info'][0]=$info;

        response(0,$rs);
    }
}
?>